package ast;

import java.util.ArrayList;

public class ExpIf implements Expresion {


	/**
	 * ATTRIBUTES
	 */
	// if y else if
	private ArrayList<IfCase>	_IfCases;
	// else
	private IfCase				_Else;
	
	/**
	 * Constructor
	 */
	public ExpIf(){
		_IfCases = new ArrayList<IfCase>();
	}
	
	/**
	 * agregar ifs a la lista
	 * @param pIfCase
	 */
	public void addIfCase( IfCase pIfCase) {
		this._IfCases.add(pIfCase);
	}
	
	/**
	 * Codigo asociado a esta expresion
	 */
	@Override
	public String GenerarCodigo() {
		String code = new String();
		// generar if
		int cnt = 0;
		String vars = _IfCases.get(cnt).getStrVar();
		code += ConstCode.IF_EXP + ConstCode.FLUJO + ConstCode.MENOR + vars + ConstCode.END_IF_EXP;
		code += _IfCases.get(cnt).GenerarCodigo();
		cnt++;
		// generar else if
		while( cnt < _IfCases.size() ){
			vars += ConstCode.SUMA + _IfCases.get(cnt).getStrVar();
			code += ConstCode.ELSE_IF + ConstCode.FLUJO + ConstCode.MENOR + vars + ConstCode.END_IF_EXP;
			code += _IfCases.get(cnt).GenerarCodigo();
			cnt++;
		}
		// generar else
		code += ConstCode.ELSE;
		code += _IfCases.get(cnt).GenerarCodigo();
		_IfCases.remove(cnt);
		/*
		 if( flujo < (var_1) ){
		 	expresions
		 } else if ( flujo < (var_1+var_2) ) {
		 	expresions
		 } else if ( flujo < (var_1+var_2+var_3) ) {
		 	expresions
		 } else {
		 	expresions
		 }		 
		*/
		return code;
	}

	/**
	 * Gets
	 */
	public ArrayList<IfCase> getIfCases() {
		return _IfCases;
	}
	
	/**
	 * Sets
	 */
	public void setElse(IfCase pElse) {
		this._Else = pElse;
	}

	
}
